package com.tanhua.dubbo.api;

import com.tan.model.mongo.FocusUser;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;

@DubboService
public class FocusUserApiimpl implements FocusUserApi{
    @Autowired
    MongoTemplate mongoTemplate;
    @Override
    public void save(Long userid, Long focusid) {
        FocusUser focusUser = new FocusUser(null, userid, focusid, System.currentTimeMillis());
        mongoTemplate.save(focusUser);
    }

    @Override
    public void delete(Long userid, Long disfocusid) {
        Criteria criteria = Criteria.where("userId").is(userid).and("focusUserId").is(disfocusid);
        mongoTemplate.remove(Query.query(criteria), FocusUser.class);
    }
}
